home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / INTERRUP.SWG / 0010_Changing the Int08 Rate.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  2KB  |  74 lines

  1. {
  2. JONATHAN WRIGHT
  3.  
  4. > A/D (analog to digital conversion).  Somehow I need to use the PC
  5. > clock/timer to call my A/D sampling interrupt at various rates from
  6. > several hundred Hz to several thousand Hz.
  7.  
  8. > Hook interrupt 1Ch and point it to your interrupt handler.  Use
  9. > a counter in this procedure to count the number of interrupts or
  10.  
  11. This will not work correctly.  Using interrupt 1Ch as it is normally set up,
  12. your interrupt routine will only be called 18 times a second (18.2, actually),
  13. so you could get a maximum of 18.2 Hz.  If you wait until a counter in this
  14. interrupt (incremented by 1 each time) reaches 1820, it will take 10 seconds!
  15. It WON'T be 100 Hz.
  16.  
  17. In order to hook the timer interrupt at a rate above 18.2 Hz, you'll need to
  18. revector int 08h (which calls int 1Ch anyway).  You'll have to set up a counter
  19. in int 08h which makes sure that the ORIGINAL int 08h routine is still called
  20. 18.2 times a second.  The value for this counter will vary, depending on how
  21. fast you set timer channel 0.  The system clock has a maximum resolution of
  22. about 1.19318 Mhz and IRQ0 is normally called 1193180/65536 times per second.
  23.  
  24. Here's some code for changing the clock rate (sorry but it's ASM):
  25. }
  26. ;*********************
  27. ; called by SetClockRate (which is Pascal callable)
  28.  
  29. ClkRate PROC NEAR
  30.  
  31.   push  ax
  32.   mov   al,36h
  33.   out   43h,al
  34.   pop   ax
  35.   out   40h,al  xchg  ah,al
  36.   out   40h,al
  37.   ret
  38. ClkRate ENDP
  39.  
  40. ;******************
  41. ; call this routine from TP as SetClockRate (Hz : WORD);
  42. SetClockRate PROC FAR
  43.  
  44. Rate EQU word ptr [bp+06]
  45.   push  bp
  46.   mov   bp,sp
  47.   cmp   rate,0
  48.   je    SCR01
  49.  
  50.   mov   ax,65535
  51.   xor   dx,dx
  52.   mov   bx,rate
  53.   div   bx
  54.   jmp   SCR02
  55.  
  56. SCR01:
  57.   xor   ax,ax
  58.  
  59. SCR02:
  60.   call  ClkRate
  61.  
  62.   mov   sp,bp
  63.   pop   bp
  64.   ret   2
  65.  
  66. SetClockRate ENDP
  67.  
  68. I pulled these procedures from some OLD code which I may have inadvertenly
  69. screwed up over time, but it looks o.k.
  70.   Actually revectoring int 08h is a bit more complex - you MUST make sure the
  71. old it 08 is called appropriately because it controls a number of system
  72. functions and your PC WILL lock up if it's not called.  I recommend finding a
  73. book to help with that part.
  74.